﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;

namespace NewsDark.Common
{
    public class ShareContract
    {
        private static TypedEventHandler<DataTransferManager, DataRequestedEventArgs> _handler;

        private string _title;
        public string Title
        {
            get
            {
                return _title;
            }
        }

        private string _description;
        public string Description
        {
            get
            {
                return _description;
            }
        }

        private Uri _url;
        public Uri Url
        {
            get
            {
                return _url;
            }
        }

        public ShareContract(string title, string description, Uri shareUri)
        {
            _title = title;
            _description = description;
            _url = shareUri;
        }
        public void ShareContent()
        {
            if (_handler != null)
                DataTransferManager.GetForCurrentView().DataRequested -= _handler;

            _handler = ShareLinkHandler;
            DataTransferManager.GetForCurrentView().DataRequested += _handler;

        }

        private void ShareLinkHandler(DataTransferManager sender, DataRequestedEventArgs e)
        {
            DataRequest request = e.Request;
            request.Data.Properties.Title = Title;
            request.Data.Properties.Description = Description;
            request.Data.SetUri(Url);
        }
    }
}
